package com.game.server.message.proto.execute;

import com.comm.ISession;

import com.game.majiang.config.DataManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.dao.XyClubInfoDao;
import com.game.server.db.entity.XyClubInfo;
import com.game.server.db.entity.XyClubMemberInfo;
import com.game.server.message.proto.in.AbstractXYmClubupdateReq;
import com.game.server.message.proto.out.XYmClubupdateRsp;

public class XYmClubupdateReq extends AbstractXYmClubupdateReq {

    @Override
    public void Execute(ISession session) {
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null && client.checkClick(msgcode)) {
            XyClubInfo clubInfo = DataManager.getInstance().getMapClub().get(this.id);
            XYmClubupdateRsp rsp = new XYmClubupdateRsp();
            rsp.setIsok(1);
            if (clubInfo != null) {
                XyClubMemberInfo player = clubInfo.getPlayer().get(client.getUserId());
                //获取系统参数
                String updateClubNameConsumeIntegral = DataManager.getInstance().systemValue("updateClubNameConsumeIntegral");
                if (player != null && (player.getIsManager() == 1 || player.getIsManager() == 2)) {
                    if (this.type == 0) {
                        if (!clubInfo.getName().equals(this.name)) {
                            rsp.setIsok(2);
                            if (client.getVo().getIntegral() >= Integer.parseInt(updateClubNameConsumeIntegral)) {
                                clubInfo.setHeadurl(this.headurl);
                                clubInfo.setContent(this.content);
                                clubInfo.setName(this.name);
                                XyClubInfoDao.updateClubByObj(clubInfo);
                                client.getVo().AddIntegral(-Integer.parseInt(updateClubNameConsumeIntegral));
                                rsp.setIsok(0);
                            }
                        } else {
                            clubInfo.setHeadurl(this.headurl);
                            clubInfo.setContent(this.content);
                            XyClubInfoDao.updateClubByObj(clubInfo);
                            rsp.setIsok(0);
                        }
                    }
                    if (this.type==1) {
                        clubInfo.setXingyuvalue(this.xingyu);
                        XyClubInfoDao.updateClubByObj(clubInfo);
                        rsp.setIsok(0);
                    }
                    rsp.setContent(clubInfo.getContent());
                    rsp.setHeadurl(clubInfo.getHeadurl());
                    rsp.setName(clubInfo.getName());
                    rsp.setXingyu(clubInfo.getXingyuvalue());
                    rsp.setId(clubInfo.getId());
                    rsp.setType(this.type);
                }
            }
            client.Send(rsp);
        }
    }

}
